package com.silverhaze.diamond.client.ui.frame;

import com.silverhaze.diamond.client.resources.ServiceResourceContainer;
import com.silverhaze.diamond.client.settings.Settings;
import com.silverhaze.diamond.client.settings.SettingsStorage;

import javax.swing.*;
import java.awt.*;

/**
 * Author: Ivan Babanin
 * © Lizard Software, 2007 y.
 */
public abstract class AbstractFrame extends JFrame {
    public static final String WIN_XP = "Windows";

    private Settings settings;

    public AbstractFrame() {
        initializeSystem();
        init();
    }

    protected void initializeSystem() {
    }

    protected void init() {
        setLayout(new BorderLayout());
        setIconImage(ServiceResourceContainer.CONTROL_PANEL.getImage());

//        if (System.getProperties().getProperty("os.name").indexOf(AbstractFrame.WIN_XP) != -1) {
//            try {
//                UIManager.setLookAndFeel(new WindowsLookAndFeel());
//            } catch (Exception e) {
//                throw new ServiceException(e, "UI", "ERROR", "can't load Windows l & f");
//            }
//        }
    }

    protected void alignFrame() {
        setLocationRelativeTo(null);
    }

    protected JButton createButton(Action a, String label, Icon ico) {
        JButton jButton = new JButton(a);

        if (label != null && !label.equals("")) {
            jButton.setText(label);
        }

        if (ico != null) {
            jButton.setIcon(ico);
        }

        return jButton;
    }

    public Settings getSettings() {
        if (settings == null) {
            settings = SettingsStorage.getSettings();
        }

        return settings;
    }
}

